<?php

define('_JEXEC', 1);
define('JPATH_BASE', realpath(dirname(__FILE__)));
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
require_once ( JPATH_BASE .'/libraries/joomla/factory.php');
require_once ( JPATH_BASE .'/libraries/social.plugins.php');


$content_id = JRequest::getInt('content_id');

//not article
if (!$content_id) die ("No article id specified");

// Initialise the application.
$app = JFactory::getApplication('site');
$app->initialise();


//get the article
$article =&JTable::getInstance('content');
$article->load($content_id);
$images  = json_decode($article->images);

//if no content for article
if (!$article->id) die ("There's content associated with this article id");

//get template
$template = & JFactory::getApplication()->getTemplate();
$article_url = 'http://' . $_SERVER['HTTP_HOST'] . JRoute::_('index.php?option=com_content&view=article&id='. $article->id);

?>

<!-- Begin VideoJS Embed-->
  <link href="<?php echo JURI::base()  . 'templates/' . $template .'/js/video-js/video-js.css'?>" rel="stylesheet">
  <link href="<?php echo JURI::base()  . 'templates/' . $template .'/css/template.css'?>" rel="stylesheet">
  <script src="<?php echo JURI::base() . 'templates/' .  $template . '/js/video-js/video.js'?>" type="text/javascript"></script>
  <script src="<?php echo JURI::base() . 'media/jui/js/jquery.min.js'?> "></script>
  <div id="video_embeded_box">
	<video id="video_preview" class="video-js vjs-default-skin" width="640" height="360" controls preload="none" poster="<?php echo JURI::base() . $images->image_fulltext?>" data-setup="{}">
	  <source src="<?php echo JURI::base() ?>images/videos/<?php echo $article->article_video ?>" type='video/mp4' />
	  <track kind="captions" src="<?php echo JURI::base() ?>images/videos/<?php echo $article->article_captions?>" srclang="en" label="English">
	  <!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. -->
	  <object id="flash_fallback_1" class="vjs-flash-fallback" width="640" height="360" type="application/x-shockwave-flash" 
		data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf">
		<param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" />
		<param name="allowfullscreen" value="true" />
		<param name="flashvars" value='config={"playlist":["<?php echo JURI::base() . $images->image_fulltext?>", {"url": "<?php echo JURI::base() ?>images/videos/<?php echo $article->article_video ?>","autoPlay":false,"autoBuffering":true}]}' />
		<!-- Image Fallback. Typically the same as the poster image. -->
		<img src="<?php echo JURI::base() . $images->image_fulltext?>" width="640" height="360" alt="Poster Image" 
		  title="No video playback capabilities." />
	  </object>
	</video>
		
		<!-- Finish image-->
		<a href="<?php echo JURI::base()?>" style="text-decoration: none;" target="_parent">
			<div id="sitepic" style="display:none;">></div>
		</a>
		<div id="replay_button"  onclick="myreplay()" style="display:none;"></div>

		<!-- Finish scripts-->
		<script type="text/javascript">
		var myPlayer = _V_("video_preview");

		var myFunc = function(){
			  var myPlayer = this;
			  // Do something when the event is fired
				jQuery('#sitepic').toggle('slow');
				jQuery('#replay_button').toggle('slow');
			};
		myPlayer.addEvent("ended", myFunc);
		var myreplay = function(){
			var myPlayer = this;
			// Do something when the event is fired
			jQuery('#sitepic').toggle('slow');
			jQuery('#replay_button').toggle('slow');
			myPlayer.play();
		};

		</script>

	  <div id="video_plugins">
		<!--Plugin Embed -->
		<div id="plg_embed">
			<script type="text/javascript">
			  function toogleEmbededCode(){
				theDiv = jQuery('#plg_embed_show_code');
				theDiv.toggle('slow');
				theDiv.children("textarea").select();
			  }	
			</script>
			<img src="<?php echo  JURI::base()?>images/embed.png" onclick="toogleEmbededCode()" />
		</div>
		<div id="plg_embed_show_code" style="display:none;">
			<textarea rows="2" >
				<iframe src="<?php echo JURI::base() . 'embeded-video.html?content_id=' . $article->id?>" frameborder="0" scrolling="NO"  width="700" height="400"/>
			</textarea>
		</div>	
			<!-- Social plugins	 -->
			<?php   SocialPlugins::renderDefaultSocialPlugins($article_url); ?>
		</div>

  </div>
  <!-- End VideoJS Embed-->	